package com.wfx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wfx.entity.PageDTO;
import com.wfx.entity.PageResult;
import com.wfx.entity.ViewOrderCunt;
import com.wfx.mapper.ViewOrderCuntMapper;
import com.wfx.service.IViewOrderCuntService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author zhu
 * @since 2021-01-27
 */
@Service
public class ViewOrderCuntServiceImpl extends ServiceImpl<ViewOrderCuntMapper, ViewOrderCunt> implements IViewOrderCuntService {
    @Autowired
    private ViewOrderCuntMapper viewOrderCuntMapper;
    //分页+条件查看订单列表
    @Override
    public PageResult<ViewOrderCunt> search(PageDTO<ViewOrderCunt> pageDTO) {
        if (pageDTO == null) {
            return new PageResult<>(false,"参数非法");
        }
        IPage<ViewOrderCunt> iPage=new Page<>(pageDTO.getPage(),pageDTO.getLimit());
        QueryWrapper<ViewOrderCunt> queryWrapper=new QueryWrapper<>();
        if (!StringUtils.isEmpty(pageDTO.getData().getOrderId())){
            queryWrapper.eq("order_time",pageDTO.getData().getOrderTime());
        }

        IPage<ViewOrderCunt> pageInfo = viewOrderCuntMapper.selectPage(iPage, queryWrapper);
        PageResult<ViewOrderCunt> pageResult=new PageResult<>();
        pageResult.setSuccess(true);
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setData(pageInfo.getRecords());
        return pageResult;
    }
}
